convert python code to api